let { User,Message,Comment } = require('../models');
const auth = require('../utils/auth');
//登录判断
let loginDone_fn = async (ctx, next) => {
    // 获取从前端传来的数据（用户信息）
    
    let uid = ctx.request.body.userName.trim() || '';
    let pwd = ctx.request.body.passWord.trim() || '';
    let res='';
    if (uid.length > 0 && pwd.length > 0) {
        let row = await User.findOne({
            where: {
                username: uid,
                password:pwd
            }
        });
        let u2Json = JSON.stringify(row);
        if(u2Json!=='null'){
            ctx.session.userId=row.id;
            ctx.session.userName=row.username;
            res={code:200,msg:'登录成功'};
        }else{
            res={code:1000,msg:'用户名或密码错误，请确认后重试'};
        }
    }else{
        res={code:1000,msg:'用户名和密码不能为空'};
    }
    ctx.body=JSON.stringify(res);
};
module.exports = {
    '/loginDone': ['post', loginDone_fn]
}